﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using wms.Common;

namespace wms.Pages
{
    /// <summary>
    /// ButtonBar.xaml 的交互逻辑
    /// </summary>
    public partial class ButtonBar : UserControl
    {
        //创建一个委托
        public delegate void ButtonClickEvent();

        public event ButtonClickEvent ClickAdd;
        public event ButtonClickEvent ClickModify;
        public event ButtonClickEvent ClickDelete;
        public event ButtonClickEvent ClickDetail;
        public event ButtonClickEvent ClickRefresh;
        public event ButtonClickEvent ClickImport;
        public event ButtonClickEvent ClickExport;
        public event ButtonClickEvent ClickPrint;
        public event ButtonClickEvent ClickVerify;
        public event ButtonClickEvent ClickExit;
        public event ButtonClickEvent ClickType;
        public event ButtonClickEvent ClickSetting;


        public Button ButtonAdd { get; set; }
        public Button ButtonModify { get; set; }
        public Button ButtonDelete { get; set; }
        public Button ButtonDetail { get; set; }
        public Button ButtonRefresh { get; set; }
        public Button ButtonImport { get; set; }
        public Button ButtonExport { get; set; }
        public Button ButtonPrint { get; set; }
        public Button ButtonVerify { get; set; }
        public Button ButtonExit { get; set; }
        public Button ButtonType { get; set; }
        public Button ButtonSetting { get; set; }

        private string _buttons;
        private bool _init = false;

        public ButtonBar()
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                ChangeLanguage.changePage(Variable.LanguageSeesion.ToString());
            }
            InitializeComponent();
        }

        private void ToolBar_Loaded(object sender, RoutedEventArgs e)
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                ToolBar toolBar = sender as ToolBar;
                var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
                if (overflowGrid != null)
                {
                    overflowGrid.Visibility = Visibility.Collapsed;
                }
                var mainPanelBorder = toolBar.Template.FindName("MainPanelBorder", toolBar) as FrameworkElement;
                if (mainPanelBorder != null)
                {
                    mainPanelBorder.Margin = new Thickness(0);
                }

                if (_init == false)
                {
                    /*
                    if (ClickAdd != null)
                    {
                        this.ButtonAdd.Click += ClickAdd;
                    }
                    if (ClickModify != null)
                    {
                        this.ButtonModify.Click += ClickModify;
                    }
                    if (ClickDelete != null)
                    {
                        this.ButtonDelete.Click += ClickDelete;
                    }
                    if (ClickDetail != null)
                    {
                        this.ButtonDetail.Click += ClickDetail;
                    }
                    if (ClickRefresh != null)
                    {
                        this.ButtonRefresh.Click += ClickRefresh;
                    }
                    if (ClickImport != null)
                    {
                        this.ButtonImport.Click += ClickImport;
                    }
                    if (ClickExport != null)
                    {
                        this.ButtonExport.Click += ClickExport;
                    }
                    if (ClickExit != null)
                    {
                        this.ButtonExit.Click += ClickExit;
                    }
                    */
                    _init = true;
                }
            }

        }


        public string Buttons
        {
            get
            {
                return _buttons;
            }

            set
            {

                _buttons = value;
                if (_buttons != null)
                {
                    string[] array = _buttons.Split(',');
                    if (array.Contains("Add"))
                    {
                        this.ButtonAdd.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Modify"))
                    {
                        this.ButtonModify.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Delete"))
                    {
                        this.ButtonDelete.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Detail"))
                    {
                        this.ButtonDetail.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Refresh"))
                    {
                        this.ButtonRefresh.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Import"))
                    {
                        this.ButtonImport.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Export"))
                    {
                        this.ButtonExport.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Print"))
                    {
                        this.ButtonPrint.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Verify"))
                    {
                        this.ButtonVerify.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Exit"))
                    {
                        this.ButtonExit.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Type"))
                    {
                        this.ButtonType.Visibility = Visibility.Visible;
                    }
                    if (array.Contains("Setting"))
                    {
                        this.ButtonSetting.Visibility = Visibility.Visible;
                    }
                }
            }
        }

        private void ToolBar_Initialized(object sender, EventArgs e)
        {
            this.ButtonAdd = this.btn_add;
            this.ButtonModify = this.btn_modify;
            this.ButtonDelete = this.btn_delete;
            this.ButtonDetail = this.btn_detail;
            this.ButtonRefresh = this.btn_refresh;
            this.ButtonImport = this.btn_import;
            this.ButtonExport = this.btn_export;
            this.ButtonExit = this.btn_exit;
            this.ButtonPrint = this.btn_print;
            this.ButtonVerify = this.btn_verify;
            this.ButtonType = this.btn_type;
            this.ButtonSetting = this.btn_setting;

            this.ButtonAdd.Visibility = Visibility.Collapsed;
            this.ButtonModify.Visibility = Visibility.Collapsed;
            this.ButtonDelete.Visibility = Visibility.Collapsed;
            this.ButtonDetail.Visibility = Visibility.Collapsed;
            this.ButtonRefresh.Visibility = Visibility.Collapsed;
            this.ButtonImport.Visibility = Visibility.Collapsed;
            this.ButtonExport.Visibility = Visibility.Collapsed;
            this.ButtonExit.Visibility = Visibility.Collapsed;
            this.ButtonPrint.Visibility = Visibility.Collapsed;
            this.ButtonVerify.Visibility = Visibility.Collapsed;
            this.ButtonType.Visibility = Visibility.Collapsed;
            this.ButtonSetting.Visibility = Visibility.Collapsed;

        }

        private void btn_add_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickAdd != null)
            {
                this.ClickAdd.Invoke();
            }
        }

        private void btn_modify_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickModify != null)
            {
                this.ClickModify.Invoke();
            }
        }

        private void btn_delete_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickDelete != null)
            {
                this.ClickDelete.Invoke();
            }
        }

        private void btn_detail_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickDetail != null)
            {
                this.ClickDetail.Invoke();
            }
        }

        private void btn_refresh_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickRefresh != null)
            {
                this.ClickRefresh.Invoke();
            }
        }

        private void btn_import_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickImport != null)
            {
                this.ClickImport.Invoke();
            }
        }

        private void btn_export_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickExport != null)
            {
                this.ClickExport.Invoke();
            }
        }

        private void btn_print_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickPrint != null)
            {
                this.ClickPrint.Invoke();
            }
        }

        private void btn_verify_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickVerify != null)
            {
                this.ClickVerify.Invoke();
            }
        }

        private void btn_exit_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickExit != null)
            {
                this.ClickExit.Invoke();
            }
        }

        private void btn_type_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickType != null)
            {
                this.ClickType.Invoke();
            }
        }

        private void btn_setting_Click(object sender, RoutedEventArgs e)
        {
            if (this.ClickSetting != null)
            {
                this.ClickSetting.Invoke();
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            string name = "woshi";
        }
    }
}
